// ---- 算子管理模块 ----
import { authedApi } from '../utils/axios'
// 获取算子分类信息
export function getCategories(project_id, params = {}) {
  return authedApi.get(`/projects/${project_id}/designer/categories/`, { params });
}
//新增算子分类信息
export function postCategories(project_id, params = {}) {
  return authedApi.post(`/projects/${project_id}/designer/categories/`, params);
}
//删除算子分类
export function deleteCategories(project_id,operator_id) {
  return authedApi.delete(`/projects/${project_id}/designer/categories/${operator_id}/`);
}
//修改算子分类
export function putCategories(project_id,operator_id,params={}) {
  return authedApi.put(`/projects/${project_id}/designer/categories/${operator_id}/`,params);
}

//获取算子信息列表
export function getOperators(project_id, params = {}) {
  return authedApi.get(`/projects/${project_id}/designer/operators/`, { params });
}
//新增或更新算子
export function postOperators(project_id, params = {}) {
  return authedApi.post(`/projects/${project_id}/designer/operators/`, params);
}
//获取算子详情
export function getOperatorsDetail(project_id, operator_id, params = {}) {
  return authedApi.get(`/projects/${project_id}/designer/operators/${operator_id}/`, params);
}

// 删除算子
export function deleteOperators(project_id, operator_id) {
  return authedApi.delete(`/projects/${project_id}/designer/operators/${operator_id}/`);
}
// 获取算子模板信息列表
export function getTemplates(project_id, params = {}) {
  return authedApi.get(`/projects/${project_id}/designer/templates/`, { params });
}

// 获取算子模板详情
export function getTemplatesDetails(project_id, template_id, params = {}) {
  return authedApi.get(`/projects/${project_id}/designer/templates/${template_id}/`, { params });

}
// 删除算子模板
export function deleteTemplates(project_id, template_id) {
  return authedApi.delete(`/projects/${project_id}/designer/templates/${template_id}/`);
}
// 算子模板排序
export function patchSequences(project_id, params = {}) {
  return authedApi.patch(`/projects/${project_id}/designer/templates/sequences/`, params);
}

// 公开模板
export function putTemplatePublic(project_id, template_id, params = {}) {
  return authedApi.put(`/projects/${project_id}/designer/templates/${template_id}/public/`, params);
}

//---- 设计器模块接口 ----
// 获取工作流
export function getWorkflows(project_id, params = {}) {
  return authedApi.get(`/projects/${project_id}/designer/workflows/`, { params });
}
// 创建工作流
export function postWorkflows(project_id, params = {}) {
  return authedApi.post(`/projects/${project_id}/designer/workflows/`, params);
}
// 删除工作流
export function deleteWorkflows(project_id, workflow_id) {
  return authedApi.delete(`/projects/${project_id}/designer/workflows/${workflow_id}/`)
}
//修改工作流
export function putWorkflows(project_id, workflow_id, parmas = {}) {
  return authedApi.put(`/projects/${project_id}/designer/workflows/${workflow_id}/`, parmas)
}
//获取工作流详情
export function getWorkflowsDetail(project_id, workflow_id) {
  return authedApi.get(`/projects/${project_id}/designer/workflows/${workflow_id}/`)
}
// 工作流运行或创建实验
export function postRunWorkflows(project_id, workflow_id, params = {}) {
  return authedApi.post(`/projects/${project_id}/designer/workflows/${workflow_id}/instances/`, params)
}
// 查询版本关联的实验

export function getRunWorkflows(project_id, workflow_id, params = {}) {
  return authedApi.get(`/projects/${project_id}/designer/workflows/${workflow_id}/instances/`, params)
}
// 查询工作流运行状态，自动更新状态
export function putRuninfos(project_id, workflow_id, instance_id) {
  return authedApi.put(`/projects/${project_id}/designer/workflows/${workflow_id}/instances/${instance_id}/runinfos/`)
}
export function getRuninfos(project_id, workflow_id, instance_id) {
  return authedApi.get(`/projects/${project_id}/designer/workflows/${workflow_id}/instances/${instance_id}/`)
}
//工作流运行日志
export function getlogs(project_id, workflow_id, instance_id, params = {}) {
  let obj = {
    params,
    responseType: 'blob'
  }
  let dataType = params.filepath.substring(params.filepath.lastIndexOf(".") + 1)
  if (dataType == 'csv' || dataType == 'html'||dataType == 'log') {
    delete obj.responseType
  }
  return authedApi.get(`/projects/${project_id}/designer/workflows/${workflow_id}/instances/${instance_id}/download/`, obj)
}
//工作流运行结果
export function getlogsResult(project_id, workflow_id, instance_id, params = {}) {
  return authedApi.get(`/projects/${project_id}/designer/workflows/${workflow_id}/instances/${instance_id}/result/`, { params })
}
//查询工作流版本
export function getVersion(project_id, template_id) {
  return authedApi.get(`/projects/${project_id}/designer/workflow_templates/${template_id}/workflows/`)
}
//算子配置文件上传
export function operatorFiles(project_id, params = {}) {
  return authedApi.post(`/projects/${project_id}/designer/files/`, params, { headers: { 'Content-Type': 'multipart/form-data' } })
}
//查询工作流实验
export function getExperiments(project_id, template_id,params={}) {
  return authedApi.get(`/projects/${project_id}/designer/workflow_templates/${template_id}/experiments/`,{params})
}
//更改工作流状态
export function putWorkflowStatus(project_id, workflow_id, instance_id, parmas = {}) {
  return authedApi.put(`/projects/${project_id}/designer/workflows/${workflow_id}/instances/${instance_id}/status/`, parmas)
}
//工作流根据版本还原
export function putRecoveries(project_id, workflow_id, parmas = {}) {
  return authedApi.put(`/projects/${project_id}/designer/workflows/${workflow_id}/recoveries/`, parmas)
}
// 查询工作流实例算子
export function experimentsOperators(project_id, workflow_id, instance_id) {
  return authedApi.get(`/projects/${project_id}/designer/workflows/${workflow_id}/instances/${instance_id}/operators/`)
}



